package top.lingkang.fv.solon;

import org.noear.solon.annotation.Controller;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.BeanWrap;
import org.noear.solon.core.Plugin;
import top.lingkang.finalvalidated.constraints.Email;
import top.lingkang.finalvalidated.constraints.HasIntValue;
import top.lingkang.finalvalidated.constraints.HasStringValue;
import top.lingkang.finalvalidated.constraints.Length;
import top.lingkang.finalvalidated.constraints.Max;
import top.lingkang.finalvalidated.constraints.Min;
import top.lingkang.finalvalidated.constraints.NotBlank;
import top.lingkang.finalvalidated.constraints.NotEmpty;
import top.lingkang.finalvalidated.constraints.NotNull;
import top.lingkang.finalvalidated.constraints.Null;
import top.lingkang.finalvalidated.constraints.Pattern;

/**
 * final-validator 插件初始化
 *
 * @author lingkang
 * Created by 2024/3/4
 */
public class FinalValidatorPlugin implements Plugin {

    @Override
    public void start(AppContext context) throws Throwable {
        context.beanRegister(new BeanWrap(context, InterceptorFinalValidator.class), null, false);
        InterceptorFinalValidator interceptor = context.getBean(InterceptorFinalValidator.class);
        context.beanInterceptorAdd(ValidParams.class, interceptor, 666);
        context.beanInterceptorAdd(Controller.class, interceptor, 667);

        // 参数注解
        context.beanInterceptorAdd(Email.class, interceptor, 666);
        context.beanInterceptorAdd(Length.class, interceptor, 666);
        context.beanInterceptorAdd(Max.class, interceptor, 666);
        context.beanInterceptorAdd(Min.class, interceptor, 666);
        context.beanInterceptorAdd(NotBlank.class, interceptor, 666);
        context.beanInterceptorAdd(NotEmpty.class, interceptor, 666);
        context.beanInterceptorAdd(NotNull.class, interceptor, 666);
        context.beanInterceptorAdd(Null.class, interceptor, 666);
        context.beanInterceptorAdd(Pattern.class, interceptor, 666);
        context.beanInterceptorAdd(HasIntValue.class, interceptor, 666);
        context.beanInterceptorAdd(HasStringValue.class, interceptor, 666);
    }
}
